package com.zr.repertory.warelocation.mapper;

import com.zr.model.QueryWareAreaByWarehouseVo;
import com.zr.model.WareLocationAddVo;
import com.zr.model.WareLocationSelectVo;
import com.zr.model.WareLocationUpdateVo;
import com.zr.util.result.ResultUtil;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by Administrator on 2019/11/21.
 */
@Mapper
public interface WareLocationMapper {

    int queryCount(WareLocationSelectVo wareLocationSelectVo);

    List<WareLocationSelectVo> queryData(WareLocationSelectVo wareLocationSelectVo);

    @Select("SELECT warehouseCode,warehouseName,warehouseDec," +
            "wareAreaCode,wareAreaName,wareAreaDec," +
            "wareLocationCode,wareLocationName" +
            "FROM warehouse h" +
            "LEFT JOIN warearea a ON a.warehouseId=h.warehouseId" +
            "LEFT JOIN warelocation l ON l.wareAreaId=a.wareAreaId" +
            "WHERE wareLocationId = #{wareLocationId}")
    WareLocationUpdateVo beforeUpdate(Integer wareLocationId);

    @Update("update warelocation set wareLocationName = #{wareLocationName}")
    ResultUtil update(@Valid WareLocationUpdateVo wareLocationUpdateVo);

    int queryLocationCount(WareLocationSelectVo wareLocationSelectVo);

    List<WareLocationSelectVo> queryLocationData(WareLocationSelectVo wareLocationSelectVo);

    //需要修改
    @Select("select warehouseCode,warehouseName from warehouseId = warehouseid")
    List<WareLocationSelectVo> queryWarehouseData();

    @Select("select wareAreaCode,wareAreaName from wareArea where wareArea.warehouseId=warehouse.warehouseId")
    List<WareLocationSelectVo>  queryWareAreaData(@Valid QueryWareAreaByWarehouseVo queryWareAreaByWarehouseVo);



    @Insert("insert into warelocation(wareLocationCode,wareLocationName) values(#{wareLocationCode},#{wareLocationName})")
    ResultUtil save(@Valid WareLocationAddVo wareLocationAddVo);
}
